<template>
    <view class="page-main">
        <liu-slide-questions ref="child" :dataList="list" @submit="subData"></liu-slide-questions>
    </view>
</template>

<script>
import {topicList} from '../../../common/api'
export default {
	data() {
		return {
			list: [], // 获取答题列表
		}
	},
	onLoad() {
		this.getTopicList()
	},
	methods: {
		// 获取答题列表
		async getTopicList(){
			let res = await topicList()
			console.log(res, 1111);
			this.list = res
		},
		//点击提交
		subData(event, data) {
			console.log(event, data, 11111);
			console.log('提交的数据：' + JSON.stringify(data))
			let answerData = []
			let selectData = []
			this.list.findIndex((currentValue, index, arr) => {
				console.log(currentValue, index, arr, 22222);
				if(event == index) {
					console.log(currentValue, 33333);
					answerData = currentValue.result
				}
			})
			data.findIndex((currentValue, index, arr) => {
				console.log(currentValue, index, arr, 7777);
				if(event == index) {
					selectData = currentValue.userAnswer
				}
			})
			console.log(selectData, this.isArray(selectData), 8888);
			if(selectData == ''){
				this.$u.toast('您还没选择选项！')
			} else {
				let newSelectData = []
				if(this.isArray(selectData)){
					this.$refs.child.callSubmit(selectData, event, answerData)
				} else {
					newSelectData.push(selectData)
					this.$refs.child.callSubmit(newSelectData, event, answerData)
				}
				
			}
		},
		// 判断是否是数组
		isArray(value) {
			return Array.isArray(value);
		}
	}
}
</script>